package com.Smart.smartscals.CustomView;

import com.Smart.smartscals.Activity.R;
import com.Smart.smartscals.Adapter.ArrayWheelAdapter;
import com.Smart.smartscals.Adapter.WheelAdapter;
import com.Smart.smartscals.Entity.EntityWheelView;
import com.Smart.smartscals.Interface.OnWheelChangedListener;
import com.Smart.smartscals.Utils.Tools;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CustomScrovieView extends LinearLayout {

	private View mView;
	private Context mContext;
	private CustomWheelView wheelView;
	private TextView tvFirstParam, tvSecondParam;
	private WeelChangeListener changeListener;

	public CustomScrovieView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		initView();
	
		setListener();

	}
	public int getCurrentItem(){
		
		return wheelView.getCurrentItem();
	}
	public void SetFirstTv(String tmpStr) {
		tvFirstParam.setText(tmpStr);
		
	}

	public void setOnWeelChangeListener(final WeelChangeListener changeListener) {
		wheelView.addChangingListener(new OnWheelChangedListener() {

			@Override
			public void onChanged(CustomWheelView wheel, int oldValue,
					int newValue) {
				changeListener.onWeelChangeListener(wheelView, oldValue,
						newValue);
			}
		});

	}

	private void setListener() {
	}

	private void initView() {

		mView = ((LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
				R.layout.customview_choice_layout, this);
		wheelView = (CustomWheelView) mView
				.findViewById(R.id.wheelview_datachoice);
		tvFirstParam = (TextView) mView.findViewById(R.id.wheelview_firstparam);
		tvSecondParam = (TextView) mView.findViewById(R.id.wheelview_firstunit);

	}

	public void startMyTration(EntityWheelView mEntityWheelView) {
		wheelView.setAdapter(mEntityWheelView.getArrayWheelAdapter());
		
		setStr(mEntityWheelView);

		wheelView.setCyclic(mEntityWheelView.isRecyle());
		wheelView.setVisibleItems(5);
		wheelView.setCurrentItem(70);
		setTextViewSize(mEntityWheelView);
	}

	private void setStr(EntityWheelView mEntityWheelView) {
		if (mEntityWheelView.getSecondStrUnit() != null)
			wheelView.setLabel(mEntityWheelView.getSecondStrUnit());
		if (mEntityWheelView.getFirstStr() != null)
			tvFirstParam.setText(mEntityWheelView.getFirstStr());
		if (mEntityWheelView.getFirsStrUnit() != null)
			tvSecondParam.setText(mEntityWheelView.getFirsStrUnit());
	}

	private void setTextViewSize(EntityWheelView mEntityWheelView) {

		tvFirstParam.setTextSize(mEntityWheelView.getSizeParam());
		tvSecondParam.setTextSize(mEntityWheelView.getSizeParamUnit());
		wheelView.setTvSizeE(mEntityWheelView.getSizeParam());

	}

	public abstract class WeelChangeListener {
		abstract public void onWeelChangeListener(CustomWheelView wheel,
				int oldValue, int newValue);
	}
}
